package top.wshape1.rpc.consumer.tolerant;

import top.wshape1.rpc.common.extension.ExtensionLoader;
import top.wshape1.rpc.config.JJRpcConfig;

/**
 * @author Wshape1
 * @version 1.0
 * @description FaultTolerantStrategy工厂类
 * @since 2024-02-15
 */

public class FaultTolerantStrategyFactory {

    private static final ExtensionLoader<FaultTolerantStrategy> loader = ExtensionLoader.getExtensionLoader(FaultTolerantStrategy.class);

    private static FaultTolerantStrategy strategy;

    public static FaultTolerantStrategy getStrategy() {
        if (strategy == null) {
            strategy = loader.getExtension(JJRpcConfig.CONFIG.getConsumer().getFaultTolerant().getStrategy());
        }
        return strategy;
    }

    public static void setStrategy(FaultTolerantStrategy faultTolerantStrategy) {
        strategy = faultTolerantStrategy;
    }


}
